{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "287a454d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.2.5\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "print(pd.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "ee71a18c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>r1</th>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r2</th>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>r3</th>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    A  B  C\n",
       "r1  1  2  3\n",
       "r2  4  5  6\n",
       "r3  7  8  9"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame(data=[[1, 2, 3], [4, 5, 6], [7, 8, 9]],\n",
    "                  index=[\"r1\", \"r2\", \"r3\"],\n",
    "                  columns=[\"A\", \"B\", \"C\"]\n",
    "                  )\n",
    "\n",
    "#省去np.array 二维tuple\n",
    "tuple等创建方式\n",
    "\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "65a1cff4",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"csv文本文件的写入\"\"\"\n",
    "\n",
    "df.to_csv('7-data.csv', index=True, encoding='utf8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "31c70025",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "    A  B  C\n",
      "r1  1  2  3\n",
      "r2  4  5  6\n",
      "r3  7  8  9\n",
      "    A  B  C\n",
      "r1  1  2  3\n",
      "r2  4  5  6\n",
      "r3  7  8  9\n"
     ]
    }
   ],
   "source": [
    "\"\"\"csv文本文件的读取\"\"\"\n",
    "\n",
    "s_load = pd.read_csv('7-data.csv',\n",
    "                     sep = \",\",\n",
    "                     header = 'infer',\n",
    "                     index_col = 0,\n",
    "                     skiprows = 0\n",
    "                    )\n",
    "print(type(s_load))\n",
    "print(s_load)\n",
    "\n",
    "\n",
    "s_load = pd.read_table('7-data.csv',\n",
    "                     sep = \",\",\n",
    "                     header = 'infer',\n",
    "                     index_col = 0,\n",
    "                     skiprows = 0\n",
    "                    )\n",
    "print(s_load)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "5a025a35",
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"Excel文件的写入\"\"\"\n",
    "\n",
    "df = pd.DataFrame(data=[[1, 2, 3], [4, 5, 6], [7, 8, 9]],\n",
    "                  index=[\"r1\", \"r2\", \"r3\"],\n",
    "                  columns=[\"A\", \"B\", \"C\"]\n",
    "                  )\n",
    "\n",
    "# 方式1\n",
    "df.to_excel(\"7-data.xlsx\", sheet_name=\"sheet1\", index=True)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
